 (function() {
  window.Dialog = (function() {
    function Dialog(map) {
      this.map = map;
      
      // find the dom elements we need to fill in later
      this.container = j$('#modal-container');
      this.elem = this.container.find('.modal');
      this.name = this.elem.find('.modal-name');
      this.subtitle = this.elem.find('.modal-subtitle');
      this.address = this.elem.find('.modal-address');
      this.cityStateZip = this.elem.find('.modal-city-state-zip');
      this.phone = this.elem.find('.modal-phone');
      this.fax = this.elem.find('.modal-fax');
      this.img = this.elem.find('.modal-image');
      this.imgHolder = this.elem.find('.modal-image-holder');
      this.link = this.elem.find('.modal-link');
      //this.imgLink = this.elem.find('.modal-image-href');
      this.bull = this.elem.find('.modal-bull');
      this.direx = this.elem.find('.modal-direx');
    }
    Dialog.prototype.render = function(point) {
      var sub;
      
      // populate the dialog from the point
      this.name.text(point.name || '');
      this.cityStateZip.text(point.cityStateZip || '');
      
      sub = point.subtitle || (function() {
        switch (point.color) {
          case 'purple':
              return this.map.locationsBulletClub;
          case 'dark_blue':
              return this.map.aPartnerHotel;
          case 'green':
              return this.map.futureOpenings;
          case 'orange':
              return this.map.aRitzReserve;
          default:
            return ''; //this value should be EMPTY
        }
      })();
      
      //注释by xiongxu 注释掉子标题
      this.subtitle.text('');//清空原先的缓存
      if (sub){
    	  this.subtitle.text(sub || '');
      }
      this.address.text(point.address || '');
      this.phone.text(point.phone ? "Phone: " + point.phone : '');
      this.fax.text(point.fax ? "Fax: " + point.fax : '');
      
      if (point.link !== 'javascript:void(0);') {
        this.link.attr('href', point.link).show();
        this.imgHolder.attr('href', point.link);
        if(point.link.length>4 && point.link.substring(0,1)!='/') {
            //alert("setting target blank!");
            this.link.attr('target', '_blank');
            this.imgHolder.attr('target', '_blank');
        } else {
            //alert("no new window! " + "[" + point.link.substring(0,1) + "] " + point.link );
            this.link.attr('target', '_self');
            this.imgHolder.attr('target', '_self');
        }
      } else {
        this.link.hide();
        this.imgHolder.attr('href', 'javascript:void(0)')
      }
      
      if (point.image) {
        this.img.attr('src', point.image).show();
      } else {
        this.img.hide();
      }
      
      if (point.direx) {
        this.direx.attr('href', point.direx).show();
        this.bull.show();
      } else {
        this.direx.hide();  
        this.bull.hide();
      }
      return this.container.html();
    };
    return Dialog;
  })();
}).call(this);